const { Sequelize } = require('sequelize');
const { SQL_DATABASE, SQL_USERNAME, SQL_PASSWORD } = require('../config/index.js');
const sequelize = new Sequelize(SQL_DATABASE, SQL_USERNAME, SQL_PASSWORD, {
    host: 'localhost',
    dialect: "mysql",
    port: 3306,
    timezone: "+08:00",
    dateString: true,
    logging: false,
    define: {
        freezeTableName: true,
    },
    dialectOptions: {
        charset: 'utf8mb4',
    }
});

(async () => {
    try {
        await sequelize.authenticate();
        console.log('Connection has been established successfully.');
    } catch (error) {
        console.error('Unable to connect to the database:', error);
    }
})()

module.exports = sequelize;